package com.sl.au.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.sl.au.entity.AfterSaleOutHouseView;

public interface AfterSaleOutHouseViewRepository extends JpaRepository<AfterSaleOutHouseView,String> {

	@Query(" select a from AfterSaleOutHouseView a where (a.afterSaleTicket.unitName like '%'+?1+'%' "
			+ "or a.afterSaleTicket.afterSaleType like '%'+?1+'%' "
			+ "or a.afterSaleTicket.manageCode like '%'+?1+'%' "
			+ "or a.afterSaleTicket.proposer like '%'+?1+'%' "
			+ "or a.afterSaleTicket.linkMan like '%'+?1+'%') ")
	Page<AfterSaleOutHouseView> getAllOutHouseTicket(String key, Pageable pageable);

	@Query(" select count(*) from AfterSaleOutHouseView a where (a.afterSaleTicket.unitName like '%'+?1+'%' "
			+ "or a.afterSaleTicket.afterSaleType like '%'+?1+'%' "
			+ "or a.afterSaleTicket.manageCode like '%'+?1+'%' "
			+ "or a.afterSaleTicket.proposer like '%'+?1+'%' "
			+ "or a.afterSaleTicket.linkMan like '%'+?1+'%') ")
	long getAllCountBykey(String key);

	@Query(" select a from AfterSaleOutHouseView a where a.number is not null and (a.afterSaleTicket.unitName like '%'+?1+'%' "
			+ "or a.afterSaleTicket.afterSaleType like '%'+?1+'%' "
			+ "or a.afterSaleTicket.manageCode like '%'+?1+'%' "
			+ "or a.afterSaleTicket.proposer like '%'+?1+'%' "
			+ "or a.afterSaleTicket.linkMan like '%'+?1+'%') ")
	Page<AfterSaleOutHouseView> getYesOutHouseTicket(String string, Pageable pageable);

	@Query(" select count(*) from AfterSaleOutHouseView a where a.number is not null and (a.afterSaleTicket.unitName like '%'+?1+'%' "
			+ "or a.afterSaleTicket.afterSaleType like '%'+?1+'%' "
			+ "or a.afterSaleTicket.manageCode like '%'+?1+'%' "
			+ "or a.afterSaleTicket.proposer like '%'+?1+'%' "
			+ "or a.afterSaleTicket.linkMan like '%'+?1+'%') ")
	long getYesCountBykey(String string);

	@Query(" select a from AfterSaleOutHouseView a where a.number is null and (a.afterSaleTicket.unitName like '%'+?1+'%' "
			+ "or a.afterSaleTicket.afterSaleType like '%'+?1+'%' "
			+ "or a.afterSaleTicket.manageCode like '%'+?1+'%' "
			+ "or a.afterSaleTicket.proposer like '%'+?1+'%' "
			+ "or a.afterSaleTicket.linkMan like '%'+?1+'%') ")
	Page<AfterSaleOutHouseView> getNoOutHouseTicket(String string, Pageable pageable);

	@Query(" select count(*) from AfterSaleOutHouseView a where a.number is null and (a.afterSaleTicket.unitName like '%'+?1+'%' "
			+ "or a.afterSaleTicket.afterSaleType like '%'+?1+'%' "
			+ "or a.afterSaleTicket.manageCode like '%'+?1+'%' "
			+ "or a.afterSaleTicket.proposer like '%'+?1+'%' "
			+ "or a.afterSaleTicket.linkMan like '%'+?1+'%') ")
	long getNoCountBykey(String string);

}
